home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
722
/
722.xpi
/
chrome
/
noscript.jar
/
content
/
noscript
/
Strings.js
< prev
next >
Wrap
Text File
|
2010-02-12
|
2KB
|
62 lines
function Strings(chromeName) {
this.chromeName = chromeName;
}
Strings.wrap = function(s, length, sep) {
if (!sep) sep = ' ';
function wrapPara(p) {
if (!length) length = 80;
if (p.length <= length) return p;
chunks = [];
var pos;
while (p.length > length) {
pos = p.lastIndexOf(sep, length);
if (pos < 0) pos = p.indexOf(sep, length);
if (pos < 0) break;
chunks.push(p.substring(0, pos));
p = p.substring(pos + 1);
}
if (chunks.length) {
res = chunks.join("\n");
if (p.length) res += "\n" + p;
return res;
} else return p;
}
if (typeof(s) != "string") s = s.toString();
var paras = s.split("\n");
for (var j = 0; j < paras.length; j++) paras[j] = wrapPara(paras[j]);
return paras.join("\n");
}
Strings.prototype = {
bundles: {},
getBundle: function(path) {
if (path in this.bundles) return this.bundles[path];
try {
return this.bundles[path] =
CC["@mozilla.org/intl/stringbundle;1"]
.getService(CI.nsIStringBundleService)
.createBundle("chrome://" + this.chromeName + "/" + path +
"/" + this.chromeName + ".properties");
} catch(ex) {
return this.bundles[path] = null;
}
},
_stringFrom: function(bundle, name, parms) {
try {
return parms ? bundle.formatStringFromName(name, parms, parms.length) : bundle.GetStringFromName(name);
} catch(ex) {
return null;
}
}
,
getString: function(name, parms) {
var s = this._stringFrom(this.getBundle("locale"), name, parms);
return s || this._stringFrom(this.getBundle("content/en-US"), name, parms) || name;
}
}